<?php
define('__ROOT__', dirname(dirname(__FILE__))); 
include_once(__ROOT__.'/includes/header.php'); 
?>
<div class="span9">
	<ul class="breadcrumb">
	<li>
		<a href="<?php echo base_url('/home'); ?>">Home</a> <span class="divider">/</span>
	</li>
	<li>
		<a href="<?php echo base_url('/classifieds'); ?>">Classifieds</a>
	</li>
	<?php if (isset($bookmark)): ?>
	<span class="divider">/</span>
	<li>
		<?php echo $bookmark; ?></a>
	</li>
	<?php endif;?>
</ul>
<form class="search_top_form" id="clsSearchfrm" method="post" action="<?php echo base_url('/classifieds/search'); ?>">						
        <ul>
            <li>
                <input type="text" value="<?php echo set_value('keyword'); ?>" id="keyword" name="keyword" placeholder="Keyword...">
            </li>
            <li>
               <select id="selectCatg" name="selectCatg" data-rel="chosen">
					<?php
					foreach ($catg as $key => $value) {
						echo '<option value="' . $key . '"';
						if (isset($selectedIndex)){
								if ((int)$selectedIndex  === (int)$key)
									echo 'selected ';
								}
						echo '>';
						echo $value;
						echo '</option>';

					}
					?>
				</select>
            </li>
            <li>
                <button class="btn btn-warning"><i class="icon-search icon-white"></i> Search Now</button>
                <a href="<?php echo base_url('/classifieds'); ?>"><u>clear results</u></a>
            </li>
        </ul>
 </form>
    
<div class="main_content detail-product">
	<p class="pull-right"> 	Filter: 
	<a href="<?php echo base_url('classifieds'); ?>">All </a> | 
	<a href="<?php echo base_url('classifieds/filter/1'); ?>">Sell </a>| 
	<a href="<?php echo base_url('classifieds/filter/2'); ?>">Buy </a>| 
	<a href="<?php echo base_url('classifieds/filter/3'); ?>">Trade </a>|
	<a href="<?php echo base_url('classifieds/filter/4'); ?>">Rent </a></p>
	<h3 class="title">
	<?php if (isset($selectedcatg))
			echo $selectedcatg . '-';
			?>Found <?php echo $num_rows; ?> LISTINGS</h3>
   <?php if (isset($search) && $num_rows > 0)  :?>
   		<?php if ($search != 0): ?>
   		Found result for Keyword:  
   		
   		<?php echo $keyword; ?><?php endif; ?>
   	<?php endif; ?>

	<?php foreach($clist as $ad): ?>
		<div class="listing-item">
			<div class="row-fluid">	
				<div class="span7">
									<div class="featured-item">
										<div class="span3">	
											<?php
												if (isset($ad->primary_image)){
													$url = '/assets/uploads/classifieds/' . $ad->primary_image;
												}else {
													$url = '/assets/uploads/dummy.png';
												}
											?>
											<a href="<?php echo site_url('classifieds/details/' . $ad->advid); ?>"><img src="<?php echo site_url($url); ?>" alt="<?php echo $ad->title; ?>" title="<?php echo $ad->title; ?>" class="img pull-left" width="140px" height="80px"></a>
											<div class="rate">
												<img src="<?php echo site_url("assets/img/products/img_rateMiniStarOn.png"); ?>"  alt="Star On">
												<img src="<?php echo site_url("assets/img/products/img_rateMiniStarOn.png"); ?>" alt="Star On">
												<img src="<?php echo site_url("assets/img/products/img_rateMiniStarOn.png"); ?>" alt="Star On">
												<img src="<?php echo site_url("assets/img/products/img_rateMiniStarOn.png"); ?>" alt="Star On">
												<img src="<?php echo site_url("assets/img/products/img_rateMiniStarOn.png"); ?>" alt="Star Off">
											</div>										
										</div>
										<div class="span9">
											<h5><a href="detail.html">
											<?php echo anchor(site_url('classifieds/details/' . $ad->advid), $ad->title, 'title=""'); ?>
											</a></h5>
											in <a href="<?php echo base_url('classifieds/browse/') . '/'. $ad->id; ?>"><?php echo $ad->cat_descriptions; ?></a> - <?php echo date ("d/m/Y",strtotime($ad->posted_date)); ?>
											<p>

											<?php
											$cleanDesc = strip_tags ($ad->description);
											 $ad->description = (strlen($cleanDesc) > 200) ? substr($cleanDesc,0,200).'...' : $cleanDesc;
											 echo $ad->description;
											?>
											</p>
											
											<i>(<?php echo anchor(site_url('classifieds/details/' . $ad->advid), 'View Details', 'title=""');?>)</i>
										</div>								
									</div>								
				</div>
				<div class="span5">
									<div class="other_info">
										<span class="label label-important price"><?php echo $ad->price_denote; ?> <?php echo $ad->price; ?></span> 
										<?php 
										if ($ad->isSpecialDiscount){
												echo 'Save '. $ad->percentage .'%   ';
												echo '<img src="' . site_url('assets/img/nego_button.gif') . '">';
											}
										?>
										<hr/>
										<p><strong>Contact Name:</strong> <?php echo $ad->contact_person; ?><br/>
										<strong>Phone:</strong> <?php echo $ad->contact_number; ?><br/>
										<strong>E-mail:</strong> <a href="<?php echo $ad->contact_email; ?>" role="button" data-toggle="modal"><?php echo $ad->contact_email; ?></a><br/></p>
										<a href=<?php echo site_url('classifieds/details/' . $ad->advid); ?>><button class="btn btn-small btn-primary"><i class="icon-envelope icon-white"></i> Send an Email</button></a>
										<a href="<?php echo 'tel:' . $ad->contact_number; ?>"><button class="btn btn-small btn-primary"><i class="icon-volume-up icon-white"></i> Click to Call</button></a>
									</div>
				</div>
			</div>
		</div>
		<?php endforeach ?>
		<?php if (strlen($pagination)): ?>
			   <div class="pagination">
				Pages: <?php echo $pagination; ?>
			   </div>
	   <?php endif ?>
			
</div>
</div>
<?php
include_once(__ROOT__.'/includes/rightnav.php');
include_once(__ROOT__.'/includes/footer.php'); 
?>
<script type="text/javascript">
               // $(".collapse").collapse();
				//$('#accordion').collapse({hide: true});
				$('#collapseOne').collapse('show');		
 </script>